Javatpoint Logo
Javatpoint Logo

C++ multimap operator<

C++ Operator< is a non-member overloaded function of multimap. This function is used to check whether the first multimap is less than other or not.

Note: Operator < sequentially compares the element of multimap and comparison will stop at first mismatch.

Syntax

Parameter

lhs: First multimap object.

rhs: Second multimap object.

Return value

It returns true if the left side of the multimap object is less than the right side of the multimap object otherwise false.

Complexity

Complexity will be constant, if the size of lhs and rhs is different.

Otherwise, up to linear in the size (equality comparisons).

Iterator validity

No changes.

Data Races

Containers, lhs and rhs are accessed.

Exception Safety

This function does not throw an exception.


Example 1

Let's see the simple example to check whether the first multimap is less than or not:

Output:

Multimap m1 is less than m2.
Multimap m1 is not less than m2.

In the above example, there are two multimaps m1 and m2. m2 contains one element and m1 is empty. When we compare both multimaps then it will display the message "multimap m1 is less than m2" and after assigning m2 to m1 both multimaps have equal element then it will display the message that "multimap m1 is not less than m2".

Example 2

Let's see a simple example:

Output:

The multimap m1 is less than the multimap m2.
The multimap m1 is not less than the multimap m3.

Example 3

Let's see a simple example:

Output:

0
1

In the above example if m1 is less than m2 then it will return 1 otherwise 0.

Example 4

Output:

1).
---------Login----------

Enter the ID and password: 
1020     xyz
ID and password you have entered: 
1020     xyz
ID and Password stored in the system:
2040     xyz@123

Incorrect ID or Password...


2).
---------Login----------

Enter the ID and password: 
2040     xyz@123
ID and password you have entered: 
2040     xyz@123
ID and Password stored in the system:
2040     xyz@123

Welcome to your Page...

In the above example, there are two multimaps m1 and m2. m1 contains stored ID and password and second multimap m2 stores user's entered ID and password. It checks whether the m1 is less than m2 or not. If ID and password of m1 is not less than m2 then login is successful otherwise login fails.


Next TopicC++ Multimap




Help Others, Please Share

facebook twitter pinterest